<template>
    <div class="big_box">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>客户关系</el-breadcrumb-item>
            <el-breadcrumb-item>客户信息</el-breadcrumb-item>
        </el-breadcrumb>
        <el-divider></el-divider>
        <el-form :model="Customer" ref="_selectfrom">
            <el-row :gutter="5">
                <el-col :span="3">
                    <el-input placeholder="编号"  v-model="Customer.CustomerNumber"></el-input>
                </el-col>
                <el-col :span="3">
                    <el-input placeholder="姓名" v-model="Customer.CustomerName"></el-input>
                </el-col>
                <el-col :span="3">
                    <el-input placeholder="电话" v-model="Customer.CustomerPhone"></el-input>
                </el-col>
                <el-col :span="3">
                    <el-input placeholder="公司" v-model="Customer.CustomerCompany"></el-input>
                </el-col>
                <el-col :span="2">
                    <el-button   icon="el-icon-search" @click="formdata"></el-button>
                </el-col>
            </el-row>
        </el-form>
        <el-row style="padding: 10px 0px">
            <el-col>
                <el-button-group>
                    <el-button class="buttongroup" type="danger" icon="el-icon-delete" @click="BatchDelete_event">批量删除</el-button>
                    <el-button class="buttongroup" type="success" icon="el-icon-circle-plus-outline" @click="AddCustomer_dialog=true">添加</el-button>
                </el-button-group>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <el-table :data="tableData" border stripe style="width: 100%"  @selection-change="SelectionChange_event">
                    <el-table-column type="selection" width="40" align="center"></el-table-column>
                    <el-table-column fixed type="index" label="序号" width="50" align="center" :index="indexMethod"></el-table-column>
                    <el-table-column fixed prop="CustomerNumber" label="客户编号" align="center" show-overflow-tooltip  width="120"></el-table-column>
                    <el-table-column prop="CustomerType " label="类型" align="center" show-overflow-tooltip  width="120">
                        <template slot-scope="slot">
                            <label v-if="slot.row.CustomerType == '1'">供货商</label>
                            <label v-if="slot.row.CustomerType == '2'">合作商</label>
                        </template>
                    </el-table-column>
                    <el-table-column prop="CustomerName" label="姓名" align="center" show-overflow-tooltip  width="120"></el-table-column>
                    <el-table-column prop="CustomerSex" label="性别" align="center" show-overflow-tooltip  width="120">
                        <template slot-scope="slot">
                            <label v-if="slot.row.CustomerSex == '1'">女</label>
                            <label v-if="slot.row.CustomerSex == '0'">男</label>
                        </template>
                    </el-table-column>
                    <el-table-column prop="CustomerBirth" label="出生日期" show-overflow-tooltip align="center" width="120">
                        <template slot-scope="slot">
                            {{ fmtDate(slot.row.CustomerBirth) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="CustomerCompany" label="公司" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="CompanyAddress" label="公司地址" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="CustomerIndustry" label="所属行业" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="MainBusines" label="主营业务" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="CustomerAddress" label="地址" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="CustomerPhone" label="电话" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="CustomerWeChat" label="微信" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="CustomerEmail" label="邮件" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="DutyParagraph" label="税号" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="OpeningBank" label="开户行" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="BankAccount" label="银行账号" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column prop="Docker" label="对接人" show-overflow-tooltip align="center">
                        <template slot-scope="slot">
                            {{ GetUserName(slot.row.Docker) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="DockingProject" label="对接项目" show-overflow-tooltip align="center">
                        <template slot-scope="slot">
                            {{ GetProjectName(slot.row.DockingProject) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="CustomerNote" label="备注" show-overflow-tooltip align="center"></el-table-column>
                    <el-table-column fixed="right" label="操作" width="250" align="center">
                        <template slot-scope="scope">
                            <el-button plain type="success" size="mini" @click="edit_event(scope.row)">编辑</el-button>
                            <el-button plain type="danger" size="mini" @click="BatchDeleteOne_event(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
            <el-col :span="24">
                <div class="block">
                    <el-pagination
                            @size-change="formdata"
                            @current-change="formdata"
                            :current-page.sync="pagination.currentPage"
                            :page-sizes="pagination.pagesizes"
                            :page-size.sync="pagination.pagesize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total.sync="pagination.total">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>

        <el-dialog :visible.sync="AddCustomer_dialog" width="80%" top="10px" title="添加客户">
            <AddCustomer :all-project="AllProject"></AddCustomer>
        </el-dialog>

        <el-dialog :visible.sync="UpdataCustomer_dialog.dialog" width="80%" top="10px" title="修改客户信息">
            <UpdataCustomer :all-project="AllProject" :customer_-template="UpdataCustomer_dialog.details" ></UpdataCustomer>
        </el-dialog>

    </div>
</template>

<script>
    import * as publicjs from "../../../public/Scriput/Public"
    import AddCustomer from "./AddCustomer";
    import UpdataCustomer from "./UpdataCustomer";

    export default {
        name: "Customer",
        components: {
            AddCustomer, UpdataCustomer,
        },
        data() {
            return {
                //表格查询数据
                Customer: {
                    CustomerNumber: '',
                    CustomerName: '',
                    CustomerPhone: '',
                    CustomerCompany: '',
                },
                //表格数据
                tableData: [],
                //分页数据绑定
                pagination: {
                    currentPage: 1,
                    pagesizes: [10, 20, 30, 40, 50],
                    pagesize: 10,
                    total: 100
                },
                //所有项目
                AllProject: [],
                //多选列表的数据集合
                SelectMore_lis: [],
                AddCustomer_dialog: false,
                UpdataCustomer_dialog: {
                    dialog: false,
                    details: {},
                },
            }
        },
        created() {
            this.Init()
            this.formdata()
        },
        methods: {
            //初始数据加载
            Init() {
                this.AllProject = publicjs.GetAllProject(this.$http)
            },
            //初始化表格数据加载
            formdata() {
                let loadding = this.openLoading();
                this.$http.post('Customer/GetCustomerDetail', {
                    currentPage: this.pagination.currentPage,
                    pagesize: this.pagination.pagesize,
                    Customer: this.Customer,
                }).then(res => {
                    loadding.close();
                    this.pagination.total = res.data.count
                    this.tableData = res.data.data
                }).catch(() => {
                    loadding.close();
                    this.$message.error('服务器异常,请联系管理员!')
                })
            },
            //表格单个删除
            BatchDeleteOne_event(obj) {
                this.SelectMore_lis.push(obj)
                this.BatchDelete_event()
            },
            //批量删除
            BatchDelete_event() {
                let idlis = []
                if (this.SelectMore_lis.length == 0) {
                    this.$message.warning('您还未选择需要删除的合同!')
                } else {
                    for (let i = 0; i < this.SelectMore_lis.length; i++) {
                        idlis.push(this.SelectMore_lis[i].Id)
                    }
                    this.$confirm('你确定要删除吗?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'error'
                    }).then(() => {
                        let loadding = this.openLoading();
                        this.$http.post('Customer/DelectCustomer', idlis).then(res => {
                            loadding.close();
                            if (res.data) {
                                this.$message.success('删除成功')
                                this.formdata()
                                this.SelectMore_lis = []
                            } else {
                                this.$message.warning('删除失败')
                            }
                        }).catch(() => {
                            loadding.close();
                            this.$message.error('服务器异常,请联系管理员!')
                        })
                    }).catch(() => {
                        this.$message.info('已取消!')
                        this.SelectMore_lis = []
                    })

                }
            },
            //编辑
            edit_event(obj) {
                this.UpdataCustomer_dialog.dialog = true
                this.UpdataCustomer_dialog.details = JSON.parse(JSON.stringify(obj))
            },
            //时间转化
            fmtDate(obj) {
                if (obj == null || obj == "") {
                    return "";
                } else {
                    return obj.split(' ')[0];
                }
            },
            //获取对应人员名字
            GetUserName(value) {
                let name = ''
                if (value != 0) {
                    for (let i = 0; i < this.$store.state.AllUsers.length; i++) {
                        if (this.$store.state.AllUsers[i].Id == value) {
                            name = this.$store.state.AllUsers[i].UserName
                            return name
                        }
                    }
                }
            },
            //获取对应人员名字
            GetProjectName(value) {
                let name = ''
                if (value != 0) {
                    for (let i = 0; i < this.AllProject.length; i++) {
                        if (this.AllProject[i].Id == value) {
                            name = this.AllProject[i].ProjectName
                            return name
                        }
                    }
                }
            },
            //表格数据选择事件
            SelectionChange_event(value) {
                this.SelectMore_lis = value
            },
            //表格数据序列号
            indexMethod(index) {
                return ((this.pagination.currentPage - 1) * this.pagination.pagesize) + index + 1
            },
        },
    }
</script>

<style scoped>

</style>
